package com.dc.refactoring._4_简化条件表达式._2_ConsolidateConditionalExpression;

/**
 * Description: 合并条件表达式
 * @author: gdc
 * @date: 2020/12/6
 * @version 1.0
 */
public class Demo {
    // 改造前
    public int fun1(int count,int base,int age){
        if (count<1){
            return 0;
        }
        if (base == 0){
            return 0;
        }
        if (age<18){
            return 0;
        }
        return 1;
    }

    // 提炼相同结果的条件
    public int fun2(int count,int base,int age){
        if (count<1 || base == 0 || age<18){
            return 0;
        }
        return 1;
    }

    // 提炼新的函数，简化逻辑
    public int fun3(int count,int base,int age){
        if (noBuy(count,base,age)){
            return 0;
        }
        return 1;
    }

    private boolean noBuy(int count,int base,int age){
        return count<1 || base == 0 || age<18;
    }

}
